package com.vx.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.vx.dao.IUserDao;
import com.vx.vo.RoleVO;
import com.vx.vo.UserVO;

@Repository("userDao")
public class UserDaoImpl implements IUserDao{

	@Autowired
	private JdbcTemplate jdbcTemplate;
	 
	@Override
	public UserVO findUserByCode(String userCode) {
		String sql="select * from s_user where userCode=? ";
		return (UserVO) jdbcTemplate.queryForObject(sql, new Object[]{userCode}, new UserMapper());
	}

	@Override
	public List<Map<String, Object>> getRoleUser(String roleCode) {
		String sql="select u.usercode from s_user u,s_userrole r where r.usercode=u.usercode and r.rolecode=? ";
		List<Map<String, Object>> userCoes=jdbcTemplate.queryForList(sql, new Object[]{roleCode});
		return userCoes;
	}

	@Override
	public RoleVO getRole(String userCode) {
		String sql="select r.* from s_role r,s_userrole ur where ur.rolecode=r.rolecode and  ur.userCode=? ";
		return (RoleVO)jdbcTemplate.queryForObject(sql, new Object[]{userCode}, new RoleMapper());
	}

	@Override
	public RoleVO getRole(int roleId) {
		String sql="select * from s_role where id=? ";
		return (RoleVO)jdbcTemplate.queryForObject(sql, new Object[]{roleId}, new RoleMapper());
	}

}
